package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.PageResult;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageResult<Activity> listActivities(Activity activity) {
        PageHelper.startPage(activity.getPage(),activity.getPageSize());
        List<Activity> activities = activityMapper.listActivities(activity);
        Page<Activity> pageInfo = (Page<Activity>) activities;
        return new PageResult<>(pageInfo.getTotal(),activities);
    }

    @Override
    public void deleteActivity(Integer id) {
        activityMapper.deleteActivity(id);
    }

    @Override
    public Activity getActivityById(Integer id) {
        return activityMapper.getActivityById(id);

    }

    @Override
    public void updateActivity(Activity activity) {
        activityMapper.updateActivity(activity);
    }

    @Override
    public void addActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activity.setCreateTime(LocalDateTime.now());
        activityMapper.addActivity(activity);
    }

    @Override
    public List<Activity> listActivitiesByType(Integer type) {
        return activityMapper.listActivitiesByType(type);
    }
}
